package net.diaowen.dwsurvey.dao.impl;

import net.diaowen.common.dao.BaseDaoImpl;
import net.diaowen.dwsurvey.dao.TreportDao;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.Iterator;
import java.util.List;
@Repository
public class TreportDaoImpl extends BaseDaoImpl implements TreportDao{
    @Override
    public String findtablevalue(String reportdescid, String civil_year, String orgid) throws Exception{
        String sql="select report_value from t_report where report_desc_id =? and civil_year = ? and org_id = ?";
        Query query=this.getSession().createSQLQuery(sql);
        query.setParameter(0,reportdescid);
        query.setParameter(1,civil_year);
        query.setParameter(2,orgid);
        List<Object []> list=query.list();
        Iterator iterator=list.iterator();
        while(iterator.hasNext()){
            return iterator.next().toString();
        }
        return "null";
    }

    @Override
    public void updatetablevalue(String value,String reportdescid, String civil_year, String orgid) throws Exception {
        System.out.println(reportdescid+civil_year+orgid);
        String sql="UPDATE t_report SET report_value = ? where report_desc_id =? and civil_year = ? and org_id = ?";
        Query query=this.getSession().createSQLQuery(sql);
        query.setParameter(0,value);
        query.setParameter(1,reportdescid);
        query.setParameter(2,civil_year);
        query.setParameter(3,orgid);
        int result=query.executeUpdate();
        System.out.println(sql);
        System.out.println(result);

        System.out.println("执行了update语句");
    }
}
